/* GUI CONVERTED from rewadja.p (converter v1.76) Fri Aug 17 03:56:13 2001 */
/* rewadja.p - REPETITIVE                                                     */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.9.3.6 $                                                         */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 03/08/95   BY: WUG *G0GQ*                */
/* REVISION: 7.3      LAST MODIFIED: 03/31/95   BY: WUG *G0K0*                */
/* REVISION: 7.3      LAST MODIFIED: 03/13/96   BY: jym *G1GD*                */
/* REVISION: 7.4      LAST MODIFIED: 10/02/97   BY: *H1FR*  Manmohan Pardesi  */

/* REVISION: 8.6E     LAST MODIFIED: 03/21/98   BY: *H1K5*  Samir Bavkar      */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Jeff Wootton       */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*               */
/* Revision: 1.9.3.5     BY: Sathish Kumar   DATE: 07/06/01 ECO: *M199*     */
/* $Revision: 1.9.3.6 $     BY: Hiral Kadakia DATE: 07/23/01 ECO: *N10F*    */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* ADJUST TRANSACTION REGISTER NET ADJUSTMENT QTY SUBPROGRAM                  */

{mfdeclre.i}
define input parameter cumwo_lot as character.
define input parameter op as integer.
define input parameter discr_acct as character.
define input parameter discr_sub as character.
define input parameter discr_cc as character.
define input parameter qty_adjust as decimal.
define input parameter rsn_code as character.
define input parameter output_reject like mfc_logical.
define input parameter emp as character.
define input parameter ophist_recid as recid.

define variable wip_qty as decimal.
define variable new_wip_qty as decimal.
define variable glx_set as character.
define variable glx_mthd as character.
define variable cur_set as character.
define variable cur_mthd as character.
define variable gl_amt like tr_gl_amt.

define new shared variable op_recno as recid.
define new shared variable opgltype like opgl_type.
define new shared variable ref like glt_ref.
define new shared variable sf_cr_acct like dpt_lbr_acct.
define new shared variable sf_cr_sub like dpt_lbr_sub.
define new shared variable sf_cr_cc like dpt_lbr_cc.
define new shared variable sf_dr_acct like dpt_lbr_acct.
define new shared variable sf_dr_sub like dpt_lbr_sub.
define new shared variable sf_dr_cc like dpt_lbr_cc.
define new shared variable sf_entity like en_entity.
define new shared variable sf_gl_amt like tr_gl_amt.

/* PROCEDURE FOR ROUNDING FOR GIVEN ROUNDING METHOD */
{gpcrnd.i}

if qty_adjust = 0 then leave.

/*NO TRANSACTION SHOULD BE PENDING HERE*/

do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

   find wr_route where wr_lot = cumwo_lot and wr_op = op exclusive-lock.

   if output_reject = yes then do:
      /*ADJUST FROM OUTPUT QUE*/
      assign
         wr_qty_outque = wr_qty_outque + qty_adjust
         wr_qty_cumoadj = wr_qty_cumoadj - qty_adjust.

      /*UPDATE REPETITIVE SCHEDULE*/
      {gprun.i ""reupdsch.p""
         "(input cumwo_lot, input op, input qty_adjust)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
   else do:
      /*ADJUST FROM REJECT QUE*/
      assign
         wr_qty_rejque = wr_qty_rejque + qty_adjust
         wr_qty_cumradj = wr_qty_cumradj - qty_adjust.
   end.

   find op_hist where recid(op_hist) = ophist_recid exclusive-lock.

   assign
      op_rsn_adjust = rsn_code
      op__dec02     = qty_adjust.

   find wo_mstr where wo_lot = cumwo_lot exclusive-lock.

   {gprun.i ""csavg01.p"" "(input wo_part, input wo_site,
            output glx_set, output glx_mthd, output cur_set, output cur_mthd)" }
/*GUI*/ if global-beam-me-up then undo, leave.


   if glx_mthd <> "avg" then do:

      find iro_det where iro_part = wo_part
         and iro_site = wo_site
         and iro_cost_set = "cumorder"
         and iro_routing = wo_lot
         and iro_op = wr_op
         no-lock.

      assign
         gl_amt = (qty_adjust * iro_cost_tot) * -1
         sf_cr_acct = wo_acct
         sf_cr_sub = wo_sub
         sf_cr_cc = wo_cc
         sf_dr_acct = discr_acct
         sf_dr_sub = discr_sub
         sf_dr_cc = discr_cc
         sf_gl_amt = gl_amt.

      find si_mstr where si_site = wo_site no-lock.
      assign
         sf_entity = si_entity
         opgltype = op_type
         op_recno = ophist_recid.

      {gprun.i ""sfopgl.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


      for first gl_ctrl
      fields (gl_rnd_mthd)
      no-lock: end.  /* FOR FIRST gl_ctrl.. */

      /* ROUND PER BASE CURRENCY ROUND METHOD */
      run gpcrnd
         (input-output gl_amt,
          input gl_rnd_mthd).

      wo_wip_tot = wo_wip_tot - gl_amt.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


end.
